<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
        String path = request.getContextPath();
			String basePath = request.getScheme() + "://"
					+ request.getServerName() + ":" + request.getServerPort()
					+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'modify.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

<script type="text/javascript" src="js/jquery-1.12.4.js"></script>
<script type="text/javascript">
	$(function() {
		$("input[name='goBack']").click(function() {
			location.href = "search.jsp";
		});
		$("input[name='goodsName']").blur(function() {
			var goodsName = $("input[name='goodsName']").val();
			if (goodsName == null || goodsName == '') {
				alert("商品名字不能为空！");
			}
		});

		$("input[name='goodsPrice']").blur(function() {
			var goodsPrice = $("input[name='goodsPrice']").val();
			if (goodsPrice == null || goodsPrice == '') {
				alert("商品价格不能为空！");
			}

			if (isNaN(goodsPrice)) {
				alert("价格必须为数字类型");
			}

			if (parseInt(goodsPrice) < 0) {
				alert("价格必须大于0");
			}

		});

		$("form").submit(function() {
			var billStatus = $("select").val();
			if (billStatus == 2) {
				alert("已处理状态无法提交！");
				return false;
			}

			var goodsName = $("input[name='goodsName']").val();
			if (goodsName == null || goodsName == '') {
				alert("商品名字不能为空！");
				return false;
			}

			var goodsPrice = $("input[name='goodsPrice']").val();
			if (goodsPrice == null || goodsPrice == '') {
				alert("商品价格不能为空！");
				return false;
			}

			if (isNaN(goodsPrice)) {
				alert("价格必须为数字类型");
				return false;
			}

			if (parseInt(goodsPrice) < 0) {
				alert("价格必须大于0");
				return false;
			}

			return true;
		});

	});
</script>

<style type="text/css">
input[type='text'] {
	width: 200px;
	margin-left: 100px;
}
</style>


</head>
<c:if test="${error!=null }">
	<script type="text/javascript">
		alert("${error}");
	</script>
</c:if>
<body>
	<div style="width:800px;margin:0 auto;">
		<form action="modify" method="post">
			<input type="hidden" value="${goods.id }" name="id" />
			<table border="1" style="width:600px;">
				<tr>
					<td>商品编号：</td>
					<td><input type="text" value="${goods.id }"
						disabled="disabled">
					</td>
				</tr>
				<tr>
					<td>商品名称：</td>
					<td><input type="text" name="goodsName"
						value="${goods.goodsName }" />
					</td>
				</tr>
				<tr>
					<td>商品价格：</td>
					<td><input type="text" name="goodsPrice"
						value="${goods.goodsPrice }" />
					</td>
				</tr>
				<tr>
					<td>库存数量：</td>
					<td><input type="text" name="goodsCount"
						value="${goods.goodsCount }" />
					</td>
				</tr>
				<tr>
					<td>订单状态：</td>
					<td><select name="billStatus">
							<c:if test="${goods.billStatus==0 }">
								<option value="${goods.billStatus }" selected="selected">待处理</option>
								<option value="1">处理中</option>
								<option value="2">已处理</option>
							</c:if>
							<c:if test="${goods.billStatus==1 }">
								<option value="${goods.billStatus }" selected="selected">处理中</option>
								<option value="0">待处理</option>
								<option value="2">已处理</option>
							</c:if>
							<c:if test="${goods.billStatus==2 }">
								<option value="${goods.billStatus }" selected="selected">已处理</option>
								<option value="1">处理中</option>
								<option value="0">待处理</option>
							</c:if>
					</select></td>
				</tr>
				<tr>
					<td colspan="1"><input style="margin-left:100px;"
						type="submit" value="提交" /><input type="button" name="goBack"
						value="返回" />
					</td>
				</tr>
			</table>
		</form>
	</div>
</body>
</html>
